//
//  MoneyViewController.m
//  Findif
//
//  Created by Mac on 2018/11/1.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "MoneyViewController.h"
#import "MoneyDetailViewController.h"
#import "WithdrawViewController.h"
#import "WithdrawViewController.h"


@interface MoneyViewController ()

@property (nonatomic, weak)UIImageView * moneyImageView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * moneyLabel;
@property (nonatomic, weak)UIButton * drawButton;

@end

@implementation MoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupNav];
    [self setupUI];
}


- (void)setupNav{
    
    self.title = @"余额";
    
//    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back(1)"] style:UIBarButtonItemStylePlain target:nil action:nil];
//    
//    self.navigationItem.backBarButtonItem = backItem;
    
    
    UIButton * rightButton = [[UIButton alloc] init];
    
    [rightButton setTitle:@"收支明细" forState:UIControlStateNormal];
    rightButton.tag = 2;
    [rightButton addTarget:self action:@selector(didNavButton:) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    
    UIBarButtonItem * rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
    self.navigationItem.rightBarButtonItem = rightBar;
}


- (void)setupUI{
    
    self.view.backgroundColor = ZRWhiteColor;
    
    UIImageView * moneyImageView = [UIImageView new];
    
    moneyImageView.image = [UIImage imageNamed:@"金币"];
    
    self.moneyImageView = moneyImageView;
    
    [self.view addSubview:self.moneyImageView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"我的余额";
    titleLabel.textColor = ZRBlackColor;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:self.titleLabel];
    
    UILabel * moneyLabel = [UILabel new];
    
    moneyLabel.textColor = ZRBlackColor;
//    moneyLabel.text = @"￥ 49.5";
    moneyLabel.text = [NSString stringWithFormat:@"￥%@",self.money];
    moneyLabel.font = [UIFont boldSystemFontOfSize:30 * SCREENH6];
    
    self.moneyLabel = moneyLabel;
    
    [self.view addSubview:self.moneyLabel];
    
    
    UIButton * drawButton = [UIButton new];
    
    [drawButton setTitle:@"提现" forState:UIControlStateNormal];
    [drawButton setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [drawButton setBackgroundColor:ZRBlackColor];
    drawButton.layer.cornerRadius = 5;
    drawButton.layer.masksToBounds = YES;
    drawButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    [drawButton addTarget:self action:@selector(clickDrawMoney) forControlEvents:UIControlEventTouchUpInside];
    
    self.drawButton = drawButton;
    
    [self.view addSubview:self.drawButton];
    
    
}


- (void)viewDidLayoutSubviews{
    
    [self.moneyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(kNavHeight+kStatusBarHeight +75 * SCREENH6);
        make.height.width.mas_equalTo(90 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.moneyImageView.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5 * SCREENH6);
        make.centerX.mas_equalTo(self.view);
    }];
    
    [self.drawButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(250 * SCREENH6);
        make.height.mas_equalTo(35 * SCREENH6);
        make.top.mas_equalTo(self.moneyLabel.mas_bottom).offset(60);
    }];
}


- (void)didNavButton:(UIButton *)button{
    
    HiddenBar;
    
    MoneyDetailViewController * detailVC = [MoneyDetailViewController new];
    
    detailVC.type = self.type;
    
    [self.navigationController pushViewController:detailVC animated:YES];
    
}


- (void)clickDrawMoney{
    
    HiddenBar;
    
    WithdrawViewController * drawVC = [WithdrawViewController new];
    
    drawVC.money = self.money;
    drawVC.state = self.type;
    
    [self.navigationController pushViewController:drawVC animated:YES];
}

@end
